package ThreadPoolDemo.bilibiliThread;

public class ThreadDeTarget {
	public interface ThreadListener {
		public void threadStart(Object source);

		public void threadFinished(Object source);
	}

	public class MyThread extends Thread {
		public ThreadListener listener;

		public void setThreadListener(ThreadListener tl) {
			this.listener = tl;
		}

		public void run() {
			if (this.listener != null)
				this.listener.threadStart(this);
			// ......

			if (this.listener != null)
				this.listener.threadFinished(this);
		}
	}

	public class Main implements ThreadListener {

		public void threadStart(Object source) {
			System.out.println("线程开始了");
		}

		public void threadFinished(Object source) {
			System.out.println("线程结束了");
		}

		private void test() {
			Thread[] threads = new Thread[10];
			for (int i = 0; i < threads.length; i++) {
				MyThread thread = new MyThread();
				thread.setThreadListener(this);
				thread.start();

				threads[i] = thread;
			}
			for (Thread thead : threads) {
				// thread.join();
			}
		}

		/*
		 * public static void main(String[] args) { test() }
		 */
	}
}
